﻿<?php
	include 'header.php';
?>
	<center><h3>Добре дошли в системата</h3>
	<h5>Моля влезте в профила си!</h5>
	<form method="POST">
		<div>Username<input type="text" name="username"/></div>
		<div>Password<input type="password" name="password"/></div>
		<div><input type="submit" value="Login"/></div>
	</form>
	<?php
		session_start();
		$connect=mysqli_connect('localhost','hristo9153',1111111,'users',3306);
		if(!$connect){
			echo 'connect failed';
		}				
		if($_POST){
			if(isset($_SESSION['IsLogged'])){
				echo 'vsi4ko e super';
				header('location: insert.php');
			}
			else{
				$username=trim($_POST['username']);
				$password=trim($_POST['password']);
				$q=mysqli_query($connect,'SELECT * FROM users WHERE user_name="'.$username.'" AND password="'.$password.'"');
				if(!$q){
					echo mysqli_error($connect);
				}		
				if($q->num_rows> 0){
					echo 'ok';
					$_SESSION['IsLogged']=true;
					header('Location: insert.php');
					exit;
				}
				else{
					echo 'login error';
				}
			}
		}	
	?>		
	</center>		
<?php
	include 'footer.php';
?>
